package com.ship.common.core.web.domain;


/**
 * @author 31463
 */
public final class JsonResult<T> {

    private Integer resultCode;

    private T resultObject;

    private String resultMsg;

    public static <T> JsonResult<T> success() {
        return result(BaseResultCode.OK, null, null);
    }

    public static <T> JsonResult<T> success(T resultObject) {
        return result(BaseResultCode.OK, null, resultObject);
    }
    public static <T> JsonResult<T> successUnify(T resultObject) {
        return result(BaseResultCode.SYS_UNIFY, null, resultObject);
    }
    public static <T> JsonResult<T> success(T resultObject,String resultMsg) {
        return result(BaseResultCode.OK, resultMsg, resultObject);
    }

    public static <T> JsonResult<T> failed(String resultMsg) {
        return result(BaseResultCode.GENERAL_ERROR, resultMsg, null);
    }

    public static <T> JsonResult<T> failed(T resultObject,String resultMsg) {
        return result(BaseResultCode.GENERAL_ERROR, resultMsg, resultObject);
    }

    public static <T> JsonResult<T> failed(ResultCode code, String resultMsg) {
        return result(code, resultMsg, null);
    }

    private static <T> JsonResult<T> result(ResultCode code, String resultMsg, T resultObject) {
        return result(code.getCode(), resultMsg, resultObject);
    }

    private static <T> JsonResult<T> result(int code, String resultMsg, T resultObject) {
        JsonResult<T> jsonResult = new JsonResult<>();
        jsonResult.setResultCode(code);
        jsonResult.setResultObject(resultObject);
        jsonResult.setResultMsg(resultMsg);
        return jsonResult;
    }
    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public T getResultObject() {
        return resultObject;
    }

    public void setResultObject(T resultObject) {
        this.resultObject = resultObject;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    @Override
    public String toString() {
        return "{" +
                "resultCode=" + resultCode +
                ", resultObject=" + resultObject +
                ", resultMsg='" + resultMsg + '\'' +
                '}';
    }
}
